package com.yuwubao.hz_International.services.impl;

import com.yuwubao.hz_International.entities.GiftConfigEntity;
import com.yuwubao.hz_International.entities.repository.GiftConfigRepository;
import com.yuwubao.hz_International.services.GiftConfigService;
import org.modelmapper.ModelMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by yangyu on 2018/1/25.
 */
@Service
public class GiftConfigServiceImpl implements GiftConfigService {

    @Autowired
    private GiftConfigRepository giftConfigRepository;

    @Resource
    private JdbcTemplate jdbcTemplate;

    @Override
    public List<GiftConfigEntity> findAll() {
        return giftConfigRepository.findAll();
    }

    @Override
    public GiftConfigEntity save(GiftConfigEntity giftConfig) {
        return giftConfigRepository.save(giftConfig);
    }

    @Override
    public GiftConfigEntity update(GiftConfigEntity giftConfig) {
        GiftConfigEntity giftConfigEntity = giftConfigRepository.findOne(giftConfig.getId());
        if (giftConfigEntity != null) {
            ModelMapper model = new ModelMapper();
            GiftConfigEntity entity = model.map(giftConfig, GiftConfigEntity.class);
            return giftConfigRepository.save(entity);
        }
        return null;
    }
}
